<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height: 280px">
                    <div class="user-info">
                        <img :src="imageURL" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name"><span>Hello:</span>{{ teacherData.teacherName }}</div>
                            <div style="height: 20px">{{ role }}</div>
                        </div>
                    </div>
                    <div class="user-info-list">
                        我的名字：
                        <span>{{ teacherData.teacherName }}</span>
                    </div>
                    <div class="user-info-list">
                        所属专业：
                        <span>{{ teacherData.studentMajor.majorName }}</span>
                    </div>
                </el-card>
                <el-card shadow="hover" style="height: 200px">
                    <div slot="header" class="clearfix">
                        <span class="user-info-list">个人详情</span>
                    </div>
                    <div class="user-info-list">
                        工号：<span class="user-info-list">{{ teacherData.teacherId }}</span>
                    </div>
                    <div class="user-info-list">
                        电话：<span class="user-info-list">{{ teacherData.teacherPhone }}</span>
                    </div>
                    <div class="user-info-list">
                        邮箱:<span class="user-info-list" style="margin-left: 80px">{{ teacherData.teacherEmail }}</span>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="16">
                <!-- <el-row :gutter="20" class="mgb20">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-lx-people grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">1234</div>
                                    <div>我的小组</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-2">
                                <i class="el-icon-lx-notice grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">321</div>
                                    <div>我的消息</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-3">
                                <i class="el-icon-lx-goods grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">5000</div>
                                    <div>我的成绩</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row> -->
                <el-card shadow="hover" style="height: 500px">
                    <div slot="header" class="clearfix">
                        <span class="user-info-list">我的消息</span>
                        <el-button style="float: right; padding: 3px 0" type="text"
                            ><router-link to="/ProjectTable">我发布的课题</router-link></el-button
                        >
                    </div>
                    <div>
                        <el-tabs v-model="message" @tab-click="readedMessage">
                            <el-tab-pane :label="`未读消息(${unread.length})`" name="first">
                                <el-table :data="unread" :show-header="false" style="width: 100%">
                                    <el-table-column>
                                        <template slot-scope="scope">
                                            <span class="message-title">{{ scope.row.message }}</span>
                                        </template>
                                    </el-table-column>

                                    <el-table-column width="120">
                                        <template slot-scope="scope">
                                            <el-button size="small" @click="handleRead(scope.row)">查看</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </el-tab-pane>
                            <el-tab-pane :label="`已读消息(${read.length})`" name="second">
                                <template v-if="message === 'second'">
                                    <el-table :data="read" :show-header="false" style="width: 100%">
                                        <el-table-column>
                                            <template slot-scope="scope">
                                                <span class="message-title">{{ scope.row.message }}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="date" width="150"></el-table-column>
                                        <el-table-column width="120">
                                            <template slot-scope="scope">
                                                <el-button type="danger" @click="handleDel(scope.$index)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </template>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Schart from 'vue-schart';
import bus from '../common/bus';
export default {
    name: 'dashboard',
    data() {
        return {
            teacherData: '',
            imageURL: '',
            item: '',
            message: 'first',
            joinMessage: '',
            unread: [],
            read: [],
            number: localStorage.getItem('ms_number'),
            role: localStorage.getItem('ms_role')
        };
    },
    computed: {
        role() {
            return this.role;
            //return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
    created() {
        this.$http.get('http://localhost:9900/teacher/TeacherData?id=' + this.number).then((res) => {
            console.log(res.data);
            this.imageURL = res.data.teacherImage;
            localStorage.setItem('imageURL', this.imageURL);
            localStorage.setItem('ms_name', res.data.teacherName);
            this.teacherData = res.data;
        });
        this.$http.get('http://localhost:9900/message/findById?receiveID=' + this.number).then((msg) => {
            console.log(this.number);
            console.log(msg.data);
            this.unread = msg.data;
        });
    },
    methods: {
        showStudentID() {
            console.log(this.studentID);
        },
        //未读消息
        handleRead(message) {
            (this.joinMessage = message), (this.checkJoin = true);
            if (message.message.indexOf('【审核消息】') != -1) {
                console.log('true');
                this.item = message.message.replace('【审核消息】', '');
            } else {
                this.checkJoin = false;
            }
        },
        handleDel(index) {
            const item = this.read.splice(index, 1);
            this.recycle = item.concat(this.recycle);
        },
        handleRestore(index) {
            const item = this.recycle.splice(index, 1);
            this.read = item.concat(this.read);
        },
        //已读消息
        readedMessage() {
            if (this.message == 'second') {
                this.$http.get('http://localhost:9900/message/findReadedMessage?receiveID=' + this.number).then((msg) => {
                    this.read = msg.data;
                    console.log(msg.data);
                });
            }
        },
        // 通过审核
        passJoin() {
            this.$http.post('http://localhost:9900/message/passJoinTeam', this.joinMessage).then((msg) => {
                this.checkJoin = false;
                this.$message.success(`审核成功！ `);
            });
        }
    },
    computed: {
        unreadNum() {
            return this.unread.length;
        }
    },
    changeDate() {
        const now = new Date().getTime();
        this.data.forEach((item, index) => {
            const date = new Date(now - (6 - index) * 86400000);
            item.name = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
        });
    },
    teamFormatter(row, column, cellValue) {
        if (cellValue.studentTeam == null) {
            return '暂无';
        } else {
            return cellValue.studentTeam.teamName;
        }
    }
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
.messageStyle {
    margin-top: 50px;
    margin-left: 50px;
}

.message-title {
    cursor: pointer;
}
.handle-row {
    margin-top: 30px;
}
</style>
